home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 4.8 KB | 161 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWObjReg.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFound.hpp"
-
- #ifndef FWOBJREG_H
- #include "FWObjReg.h"
- #endif
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #ifndef FWPRIMEM_H
- #include "FWPriMem.h"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #pragma segment FWArchiv
-
-
- //========================================================================================
- // CLASS FW_CObjectRegistry
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CObjectRegistry::~FW_CObjectRegistry
- //----------------------------------------------------------------------------------------
-
- FW_CObjectRegistry::~FW_CObjectRegistry()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CObjectRegistry::FW_CObjectRegistry
- //----------------------------------------------------------------------------------------
-
- FW_CObjectRegistry::FW_CObjectRegistry()
- {
- }
-
- //========================================================================================
- // CLASS FW_CBasicObjectRegistry
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CBasicObjectRegistry::~FW_CBasicObjectRegistry
- //----------------------------------------------------------------------------------------
-
- FW_CBasicObjectRegistry::~FW_CBasicObjectRegistry(void)
- {
- FW_PrimitiveFreeBlock(fList);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBasicObjectRegistry::FW_CBasicObjectRegistry
- //----------------------------------------------------------------------------------------
-
- FW_CBasicObjectRegistry::FW_CBasicObjectRegistry(void) :
- fList(0),
- fListLength(0),
- fPhysicalListLength(0),
- fNextUnusedID(1)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBasicObjectRegistry::GrowList
- //----------------------------------------------------------------------------------------
-
- void FW_CBasicObjectRegistry::GrowList()
- {
- long bytesNeeded = (fPhysicalListLength+kExpansion) * sizeof(SAssociation);
- if (fList == 0)
- fList = (SAssociation*) FW_PrimitiveAllocateBlock(bytesNeeded);
- else
- fList = (SAssociation*) FW_PrimitiveResizeBlock(fList, bytesNeeded);
-
- for (long i=fPhysicalListLength; i<fPhysicalListLength+kExpansion; i++)
- InitAssociation(fList[i]);
-
- fPhysicalListLength += kExpansion;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBasicObjectRegistry::Register
- //----------------------------------------------------------------------------------------
-
- FW_CObjectRegistry::ID FW_CBasicObjectRegistry::Register(const void *object)
- {
- FW_ASSERT(Lookup(object) == kNotInRegistry);
- if (fListLength == fPhysicalListLength)
- GrowList();
- long entry = fListLength++;
- fList[entry].fObject = object;
- while (Lookup(fNextUnusedID) != 0)
- fNextUnusedID++;
- fList[entry].fID = fNextUnusedID++;
- return fList[entry].fID;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBasicObjectRegistry::Register
- //----------------------------------------------------------------------------------------
-
- void FW_CBasicObjectRegistry::Register(const void *object, FW_CObjectRegistry::ID id)
- {
- FW_ASSERT(Lookup(object) == kNotInRegistry);
- FW_ASSERT(Lookup(id) == 0);
- if (fListLength == fPhysicalListLength)
- GrowList();
- long entry = fListLength++;
- fList[entry].fObject = object;
- fList[entry].fID = id;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBasicObjectRegistry::Lookup
- //----------------------------------------------------------------------------------------
-
- FW_CObjectRegistry::ID FW_CBasicObjectRegistry::Lookup(const void *object)
- {
- FW_CObjectRegistry::ID result = kNotInRegistry;
- for (long i = 0; i<fListLength; i++)
- {
- if (fList[i].fObject == object)
- {
- result = fList[i].fID;
- break;
- }
- }
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBasicObjectRegistry::Lookup
- //----------------------------------------------------------------------------------------
-
- const void* FW_CBasicObjectRegistry::Lookup(FW_CObjectRegistry::ID id)
- {
- const void* result = 0;
- for (long i = 0; i<fListLength; i++)
- {
- if (fList[i].fID == id)
- {
- result = fList[i].fObject;
- break;
- }
- }
- return result;
- }
-